﻿using System;

namespace zijian666.Http;

/// <summary>
/// 以单链结构描述一组请求头 
/// </summary>
public readonly struct SinglyLinkedHeader
{
    /// <summary>
    /// 请求头名称
    /// </summary>
    public readonly string Name;
    /// <summary>
    /// 请求头的值
    /// </summary>
    public readonly string Value;
    /// <summary>
    /// 是否是默认请求头
    /// </summary>
    public readonly bool IsDefalutValue;
    /// <summary>
    /// 下一个请求头
    /// </summary>
    public SinglyLinkedHeader? Prev => _prev is SinglyLinkedHeader a ? (SinglyLinkedHeader?)a : null;

    private readonly ValueType _prev;
    /// <summary>
    /// 构造函数
    /// </summary>
    public SinglyLinkedHeader(string name, string value, bool isDefalutValue, SinglyLinkedHeader? prev)
    {
        Name = name ?? throw new ArgumentNullException(nameof(name));
        Value = value ?? throw new ArgumentNullException(nameof(value));
        IsDefalutValue = isDefalutValue;
        _prev = prev;
    }
}
